<template>
  <div id="user-register-page">
    <h1>触图万象 用户注册</h1>
    <div class="title">企业级智能协同图库</div>
    <a-form :model="formState" name="normal_register" class="register-form" @finish="submitForm">
      <a-form-item name="userAccount" :rules="[{ required: true, message: '请输入用户名!' }]">
        <a-input v-model:value="formState.userAccount" placeholder="请输入用户名">
          <template #prefix>
            <UserOutlined class="site-form-item-icon" />
          </template>
        </a-input>
      </a-form-item>

      <a-form-item name="userPassword" :rules="[{ required: true, message: '请输入密码！' }]">
        <a-input-password v-model:value="formState.userPassword" placeholder="请输入密码">
          <template #prefix>
            <LockOutlined class="site-form-item-icon" />
          </template>
        </a-input-password>
      </a-form-item>

      <a-form-item name="checkPassword" :rules="[{ required: true, message: '请重复密码！' }]">
        <a-input-password v-model:value="formState.checkPassword" placeholder="请重复密码">
          <template #prefix>
            <LockOutlined class="site-form-item-icon" />
          </template>
        </a-input-password>
      </a-form-item>

      <a-form-item>
        <a-form-item no-style>
          <a-button @click="router.push('/user/login')">返回登录</a-button>
        </a-form-item>
      </a-form-item>

      <a-form-item>
        <a-button
          :disabled="disabled"
          type="primary"
          html-type="submit"
          class="register-form-button"
        >
          暂时不允许注册
        </a-button>
      </a-form-item>
    </a-form>
  </div>
</template>
<script lang="ts" setup>
import { computed, reactive } from 'vue'
import { LockOutlined, UserOutlined } from '@ant-design/icons-vue'
import { userRegisterUsingPost } from '@/api/userController.ts'
import { useRouter } from 'vue-router'

const formState = reactive<API.UserRegisterRequest>({
  userAccount: 'luqi',
  userPassword: '12345678',
  checkPassword: '12345678',
})

const router = useRouter()
const submitForm = async () => {
  const res = await userRegisterUsingPost(formState)

  if (res.data.code != 0) {
    return
  }
  //   跳转到登录页
  await router.replace({
    path: '/user/login',
  })
}

const disabled = computed(() => {
  return true;
})
</script>
<style scoped lang="scss">
.register-form {
  max-width: 600px;
  margin: 0 auto;
}

h1 {
  text-align: center;
  margin-bottom: 20px;
  font-size: 29px;
}

.title {
  font-size: 20px;
  margin-bottom: 20px;
  text-align: center;
  color: #bbb;
}

.register-form-button {
  width: 100%;
}
</style>
